<?php
    class ProfessorModel extends CI_Model{
     
        public function get($id){
            $this->db->where('id',$id);
            return $this->db->get('usuario')->row();
        }
        
        public function listar(){
            $this->db->order_by('nome');
            $this->db->where('perfil_id',1);
            return $this->db->get('usuario')->result();
        }
        
        public function cadastrar($dados){
            return $this->db->insert('usuario', $dados);
        }
        
        public function editar($dados){
            $this->db->where('id', $dados['id']);
            return $this->db->update('usuario',$dados);
        }
        
        public function excluir($id){
            $this->db->where('id', $id);
            return $this->db->delete('usuario');
        }
        
        public function drop(){
            $this->db->select('id,nome');
            $this->db->where('perfil_id',1);
            $this->db->order_by('nome');
            $values = $this->db->get('usuario')->result_array();
            
            $options = array();
            $options[''] = '- Selecione -';
            foreach($values as $value){
                $options[$value['id']] = $value['nome'];
            }
            return $options;
        }
        
        public function dropSemestres(){
            $this->db->select('semestre');
            $this->db->distinct();
            $this->db->order_by('semestre');
            $values = $this->db->get('turma')->result_array();
            
            $options = array();
            $options[''] = '- Selecione -';
            foreach($values as $value){
                $options[$value['semestre']] = $value['semestre'];
            }
            return $options;
        }
        
        public function getTurmasProfessor($id){
            $this->db->where('professor_id',$id);
            $this->db->select('turma.id, disciplina, letra');
            $this->db->join('disciplina','disciplina.id = turma.disciplina_id');
            return $this->db->get('turma')->result();
        }
        
    }
?>
